package cn.kk.jump;

import java.awt.image.BufferedImage;
import java.util.Random;

public class Box extends State{
    public int width=97;
    public int height=30;
    public int x;
    public int y;
    public int speed=2;


    /**重写getImage()获取对象的图片*/
    public BufferedImage getImage() {
        if (isLive()) {
            return Images.box;
        }else if (isDead()) {
            state=REMOVE;
        }
        return null;//删除状态时,不返回图片
    }
    /**箱子移动*/
    public void step(){
        Random rand= new Random();
        Random sp = new Random();
        speed=sp.nextInt(10);
        int index = rand.nextInt(2);//分别从左边出还是右边出
        if (index<1){
            x=0;
            x+=speed;
        }else if (index>1){
            x=World.WIDTH+this.width;
            x-=speed;
        }
    }

    public void yStep(){
        Box[] bb={};
        for (int i = 0; i < bb.length; i++) {
            if (bb[bb.length-1].y>=World.HEIGHT/2){
                y=bb[i].y-y;
            }else {
                return;
            }
        }
    }
}
